home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
Guide2.aspx.cs588
< prev
next >
Wrap
Text File
|
2008-02-23
|
30KB
|
633 lines
using System;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using GBPVR.Public;
using GBPVRSchedule;
using gbweb.classes;
namespace gbweb
{
/// <summary>
/// Summary description for guide.
/// </summary>
public partial class guide2 : Page
{
protected HtmlImage IMG4;
protected HtmlImage IMG5;
private DateTime startTime;
private Settings guideParams;
//Guide display values that are stored in the users cookie
private static int minuteSpan;
private static int minuteInterval;
private static int minuteSlice;
private static string useChannelIcons;
private static string channelIconHeight;
private static string channelIconWidth;
private GuideListing Guide;
protected void Page_Load(object sender, EventArgs e)
{
guideParams = Global.Settings;
Session["GuideStartTime"] = null;
GetCookieValues();
//Code to prevent Guest users from accessing the Admin and search Pages
if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
{
NAV_SEARCH.Visible = false;
NAV_CONFIG.Visible = false;
}
if (!IsPostBack)
{
//Set the header tab of the Guide to active
NAV_GUIDE.Attributes.Add("class", "currentTab");
NAV_RECORDINGS.Visible = guideParams.showManage;
if (Convert.ToBoolean((string)Session["NotGuestUser"]))
{
NAV_SEARCH.Visible = guideParams.showSearch;
}
NAV_VIDEO.Visible = guideParams.showVideoLib;
NAV_MUSIC.Visible = guideParams.showMusicLib;
NAV_PHOTO.Visible = guideParams.showPhotoLib;
NAV_STATS.Visible = guideParams.showStats;
// populate date/time navigation controls
DateTime today = DateTime.Today;
for (int hours = 0; hours < 24; hours++)
{
DateTime theHour = today.AddHours(hours);
for (int minutes = 0; minutes < 60; minutes = minutes + minuteInterval)
{
DateTime theMinute = theHour.AddMinutes(minutes);
ListItem myLI = new ListItem(theMinute.ToShortTimeString(), theMinute.ToString("HH:mm"));
timeJump.Items.Add(myLI);
}
}
Global.FillGenreList(genreList);
}
if (ViewState["GuideStartTime"] == null)
{
if (guideParams.guideStartTime != "")
{
// default the start time to the configured default start time
startTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + guideParams.guideStartTime);
}
else
{
// default to current time if the user has just logged in, or come from the 'manage recordings' page
startTime = DateTime.Now;
}
// remove seconds and miliseconds
startTime = startTime.AddSeconds(-startTime.Second);
startTime = startTime.AddMilliseconds(-startTime.Millisecond);
}
else
{
startTime = (DateTime)ViewState["GuideStartTime"];
}
//This checks to see if the user clicked next or previous to go to the next or go back to the previous
//timeline
if (Request.Form["__EVENTTARGET"] != null)
{
if (Request.Form["__EVENTTARGET"].IndexOf("viewleftbutton") != -1) ViewLeftButton_Click(null, null);
if (Request.Form["__EVENTTARGET"].IndexOf("viewrightbutton") != -1) ViewRightButton_Click(null, null);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
//Jump to the date and time that the user selected
protected void GoButton_Click(object sender, EventArgs e)
{
startTime = DateTime.Parse(dateJump.SelectedValue + " " + timeJump.SelectedValue);
}
//Go back to the previous timeline
private void ViewLeftButton_Click(object sender, ImageClickEventArgs e)
{
startTime = startTime.AddMinutes(-minuteSpan);
}
//Go to the next timeline
private void ViewRightButton_Click(object sender, ImageClickEventArgs e)
{
startTime = startTime.AddMinutes(minuteSpan);
}
protected void Page_PreRender(object sender, EventArgs e)
{
Schedule scheduleHelper = Global.Schedule;
ProgrammeDisplay2 displayProgramme = new ProgrammeDisplay2();
// build up a list of the recording we already know about
IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
// normalize time period
startTime = startTime.AddMinutes(-startTime.Minute % minuteInterval);
DateTime endTime = startTime.AddMinutes(minuteSpan);
//Set the Day/date/time display on the header
viewDate.InnerText = startTime.ToLongDateString().Trim();
serverTime.InnerText = "Server Time: " + DateTime.Now.ToLongTimeString().Trim();
// store start time away for later use
ViewState["GuideStartTime"] = startTime;
// select the correct minutes setting
timeJump.SelectedValue = startTime.ToString("HH:mm");
//Build the drop down list of days and times the user can jump to
int listoffset = (startTime.Date - DateTime.Today).Days;
if (listoffset < 0) listoffset = 0;
if (listoffset > 6) listoffset = 6;
DateTime jumpDate = startTime.AddDays(-listoffset);
dateJump.Items.Clear();
for (int nCount = -1; nCount <= 14; nCount++)
{
DateTime theDay = jumpDate.AddDays(nCount);
//ListItem myLI = new ListItem(theDay.ToLongDateString(), theDay.ToShortDateString());
ListItem myLI = new ListItem(theDay.ToString("ddd, MMM dd, yyyy"), theDay.ToShortDateString());
dateJump.Items.Add(myLI);
}
dateJump.SelectedValue = startTime.ToShortDateString();
// retrieve listings for time period
IList listingsForPeriod;
listingsForPeriod = scheduleHelper.GetListingsForTimePeriod(startTime.AddSeconds(1), endTime);
((ArrayList)listingsForPeriod).Sort(new ChannelNumberComparer());
//Check to see if the user has selected a Genre to filter the shows on
CaseInsensitiveComparer caseInsensitiveComparer = new CaseInsensitiveComparer();
string genreFilter = genreList.SelectedValue;
if ((genreFilter != null) && (genreFilter.Length == 0)) genreFilter = null;
//Create a new guide object
Guide = new GuideListing(Response);
//The below variables are used to calculate where the programs should fall on the timeline.
//
//Set the variable for the default channel column margin
int channelColMargin = 7;
//Set the variable for programme offset margin to be in the correct position
int time_margin = channelColMargin;
//Set the display line remaining variable
int remainingDisplay = 100 - time_margin;
//Default the running width
int runWidth = 0;
//Default the running margin
int runMargin = channelColMargin;
//Default the running time
int runTime = 0;
//set the corner block of the header of showtimes
Guide.addShowtimesLineLeftCorner(time_margin, true);
//set the variable to show the right hand scroll to next timeline page to false
bool showRightScroll = false;
//set the times that are to be shown along the top of the guide
for (int mins = 0; mins < minuteSpan; mins += minuteInterval)
{
//Increment the running time
runTime += minuteInterval;
//Calculate the correct width
int width = Convert.ToInt32(Math.Floor(Convert.ToDecimal((Convert.ToDecimal(Convert.ToDecimal(runTime) / Convert.ToDecimal(minuteSpan))) * remainingDisplay))) - runWidth;
//Increment the running width
runWidth += width;
//Increment the running margin
runMargin += width;
//Check to make sure that the width we just calculated does not exceed the max of the display area
if (runWidth > remainingDisplay)
{
width = width - (runWidth - remainingDisplay);
runWidth = remainingDisplay;
}
if (runMargin == 100)
{
showRightScroll = true;
}
Guide.addShowtimesLine((runMargin - width), width, startTime.AddMinutes(mins).ToShortTimeString());
}
//Output the timeline header
forcedScrollbar.InnerHtml = Guide.getGuide();
//Reintialize the guide listing control
Guide.Initailize();
//Set the divsion id variable to the intitial value
string divIdValue = "guideRow";
//Create a divsion for each channel
foreach (Channel channel in listingsForPeriod)
{
//Start off by assuiming we are not going to show the channel line. We only want to show it if
//there is at least one programme to display
bool showChannel = false;
//Set the channel name and number
string channelName = channel.getName();
if (channelName.StartsWith(channel.getChannelNumber().ToString())) // cosmetic stuff for my american friends
{
if (channelName != channel.getChannelNumber().ToString())
{
channelName = channelName.Substring(channel.getChannelNumber().ToString().Length + 1);
}
else
{
channelName = "";
}
}
//Check to see if there is a channel icon for the channel
string chnl = channel.getChannelNumber().ToString();
string channelIcon = GetChannelIcon(channel.getChannelNumber(), new string[] { channel.getName(), channelName });
//Set variable used in calculting the shows position on the timeline
DateTime prevEndTime = startTime;
//Running variables used to position the show correctly on the timeline
//
//Set the display line remaining variable
remainingDisplay = 100 - channelColMargin;
//Default the running width
runWidth = 0;
//Default the running margin
runMargin = channelColMargin;
//Default the running time
runTime = 0;
//Variable used to signify that we have or have not found at least one show....as soon as a
//show is found then we will create the line for the channel....otherwise (nothing being found)
//the channel will not show up on the listing
bool deadChannel = true;
//Loop through each programme for the channel to format it for display
foreach (Programme programme in channel.getProgrammeList())
{
int startMinutes = 0;
int endMinutes = 0;
DateTime programStartTime = programme.getStartTime();
// check to see if there are 'gaps' in the schedule that we need to pad
if (prevEndTime < programStartTime)
{
TimeSpan stimespan = prevEndTime.Subtract(startTime);
startMinutes = (int)Math.Round(stimespan.TotalMinutes);
TimeSpan etimespan = programme.getStartTime().Subtract(startTime);
endMinutes = (int)Math.Round(etimespan.TotalMinutes);
//Add a dummy filler cell to ensure the programm falls in the right spot on the timeline
//Increment the running time
runTime += (endMinutes - startMinutes);
int width = Convert.ToInt32(Math.Floor(Convert.ToDecimal((Convert.ToDecimal(Convert.ToDecimal(runTime) / Convert.ToDecimal(minuteSpan))) * remainingDisplay))) - runWidth;
//Increment the running width
runWidth += width;
//Increment the running margin
runMargin += width;
//Check to make sure that the width we just calculated does not exceed the max of the display area
if (runWidth > remainingDisplay)
{
width = width - (runWidth - remainingDisplay);
runWidth = remainingDisplay;
}
Guide.addDisplayLine("listing", (runMargin - width), width, "<div class=\"showTitle\" title=\"No Programming Available\">No Programming Available</div>");
}
else if (prevEndTime > programStartTime)
{
//This allows for programs that overlap, we just let the previous program spill into the next
// and the later program looks like it starts later
programStartTime = prevEndTime;
}
//Calculate start minutes
if (programStartTime <= startTime)
{
startMinutes = 0;
}
else
{
TimeSpan timespan = programStartTime.Subtract(startTime);
startMinutes = (int)Math.Round(timespan.TotalMinutes);
}
//Calculate end minutes
if (programme.getEndTime() >= endTime)
{
endMinutes = minuteSpan;
}
else
{
TimeSpan timespan = programme.getEndTime().Subtract(startTime);
endMinutes = (int)Math.Round(timespan.TotalMinutes);
}
//Check for programs that we can't display,
// they may either be too narrow, or
// they overlap with other programs
if ((endMinutes - startMinutes) / minuteSlice < 1) continue;
prevEndTime = programme.getEndTime();
//Assume that we will be displaying the programme currently being processed
bool showProgramme = true;
//Check to see if the user selected a genrea filter
//if (genreFilter != null && genreFilter.Length > 0)
if (genreFilter != "Choose Genre...")
{
//If there are genres on the programme check to see if it matches what the user selected
if (programme.getGenreList().Count > 0)
{
ArrayList showGenres = new ArrayList(programme.getGenreList());
showGenres.Sort();
int idx = showGenres.BinarySearch(genreList.SelectedValue, caseInsensitiveComparer);
showProgramme = idx > -1;
}
//Since no genres were on the programme then exclude it from view
else
{
showProgramme = false;
}
}
//Since we are still showing the programme we need to place it on the timeline in the correct
//position
if (showProgramme)
{
ScheduledRecording scheduledRecording = null;
if (knownRecordings.Contains(programme.getOID())) scheduledRecording = (ScheduledRecording)knownRecordings[programme.getOID()];
//We are using a TableCell to hold the formatted display information only....it is just a container
//
TableCell programmeCell = new TableCell();
//Call the common routine to format the display information
displayProgramme.FillProgrammeDisplay(Server, programmeCell, programme, scheduledRecording, true);
//Increment the running time
runTime += (endMinutes - startMinutes);
int width = Convert.ToInt32(Math.Floor(Convert.ToDecimal((Convert.ToDecimal(Convert.ToDecimal(runTime) / Convert.ToDecimal(minuteSpan))) * remainingDisplay))) - runWidth;
//Increment the running width
runWidth += width;
//Increment the running margin
runMargin += width;
//Check to make sure that the width we just calculated does not exceed the max of the display area
if (runWidth > remainingDisplay)
{
width = width - (runWidth - remainingDisplay);
runWidth = remainingDisplay;
}
//Set the correct color display for the listing based on the CssClass that was passed back
//on the TableCell by the common display formatting routine
string displayClass = programmeCell.CssClass;
//If showChannel is false it means we have not yet produced a line for the channel so
//we need to create the start of the line which holds the channel name and icon
if (!showChannel)
{
//Set the variable so that we do not come back through here again for this channel
showChannel = true;
//Start the guide area for the actual programme listings for the current channel
Guide.addStartDivLine("ch" + chnl, "guideRow");
//Set the display class for the users channel icon/text selection
string dispClass = string.Empty;
if (useChannelIcons == "chnlBoth")
{
dispClass = "channelInfoLogoAndText";
}
else
{
if (useChannelIcons == "chnlText")
{
dispClass = "channelInfo";
}
else
{
dispClass = "channelInfoLogoOnly";
}
}
//If there is a channel icon to display we need to set the appropriate formatting based on the
//display % that the user has selected in the Config page
if (channelIcon != null)
{
//Add the channel information to the Array that holds all the display information for the guide
Guide.addDisplayChannel(dispClass, chnl + " " + channelName, channelColMargin, "SearchResults2.aspx?listChannels=" + chnl + "&srtOrder=title\"",
chnl, channelName, "SearchResults2.aspx?listChannels=" + chnl + "&srtOrder=title\"", Download.GetDownloadUrl(false, true, Download.InternalFiles.ChannelIcon, Server.UrlEncode(channelIcon)));
}
else
{
//Since there is no channel icon format the line appropriatley and add it to the Array
//that holds all the display information for the guide
Guide.addDisplayChannel("channelInfo", chnl + " " + channelName, channelColMargin, "SearchResults2.aspx?listChannels=" + chnl + "&srtOrder=title\"",
chnl, channelName, "", "");
}
}
//Add the formatted programme information to the Array that holds all the display information for the guide
Guide.addDisplayLine(displayClass, (runMargin - width), width, programmeCell.Text);
}
//We are not going to display the current programme but we still need to update variables
//used to position the next programme
else
{
//Increment the running time
runTime += (endMinutes - startMinutes);
//Calculate the correct width
int width = Convert.ToInt32(Math.Floor(Convert.ToDecimal((Convert.ToDecimal(Convert.ToDecimal(runTime) / Convert.ToDecimal(minuteSpan))) * remainingDisplay))) - runWidth;
//Increment the running width
runWidth += width;
//Increment the running margin
runMargin += width;
//Check to make sure that the width we just calculated does not exceed the max of the display area
if (runWidth > remainingDisplay)
{
width = width - (runWidth - remainingDisplay);
runWidth = remainingDisplay;
}
}
}
//Set the end the line for the current channel as long as there was at least one show on that
//channel to display
if (showChannel)
{
Guide.addEndDivLine();
}
}
//This fills the content area with all the guide information that was built in the Array
CONTENTS.InnerHtml = Guide.getGuide();
CONTENTS.Attributes.Add("onscroll", "fScroll(this)");
//Reset the Guide object to dump everything from memory
Guide.Initailize();
//Get rid of the displayProgramme object
displayProgramme.Dispose();
}
private void GetCookieValues()
{
HttpCookie cookie = Request.Cookies["minuteSpan"];
minuteSpan = cookie != null ? Convert.ToInt32(cookie.Value) : 120;
cookie = Request.Cookies["minuteInterval"];
minuteInterval = cookie != null ? Convert.ToInt32(cookie.Value) : 30;
cookie = Request.Cookies["minuteSlice"];
minuteSlice = cookie != null ? Convert.ToInt32(cookie.Value) : 1;
cookie = Request.Cookies["useChannelIcons"];
useChannelIcons = cookie != null ? cookie.Value : "chnlText";
cookie = Request.Cookies["channelIconHeight"];
channelIconHeight = cookie != null ? cookie.Value : "";
cookie = Request.Cookies["channelIconWidth"];
channelIconWidth = cookie != null ? cookie.Value : "";
}
private static string channelIconPath;
private static string[] channelIconExtensions;
public string GetChannelIcon(int channelNumber, string[] channelNames)
{
// Get the Channel Icon Directory
if (channelIconPath == null)
{
lock (typeof(guide2))
{
if (channelIconPath == null)
{
channelIconPath = Path.Combine(Global.Settings.GetInstallDir(), @"media\ChannelLogos");
channelIconExtensions = Global.Settings.channelIconExtensions.Split(',');
}
}
}
Hashtable channelIconCache = (Hashtable)Cache["channelIconCache"];
if (channelIconCache == null)
{
lock (typeof(guide2))
{
channelIconCache = (Hashtable)Cache["channelIconCache"];
if (channelIconCache == null)
{
channelIconCache = new Hashtable();
Cache.Add(
"channelIconCache",
channelIconCache,
new CacheDependency(channelIconPath),
DateTime.MaxValue,
//DateTime.Now.AddMinutes(30),
//TimeSpan.Zero,
Cache.NoSlidingExpiration,
CacheItemPriority.Normal,
null);
}
}
}
if (channelIconCache.ContainsKey(channelNumber))
{
return (string)channelIconCache[channelNumber];
}
lock (channelIconCache)
{
if (channelIconCache.ContainsKey(channelNumber))
{
return (string)channelIconCache[channelNumber];
}
string channelIconFile = null;
foreach (string channelName in channelNames)
{
foreach (string channelIconExtension in channelIconExtensions)
{
string cleanName = channelName;
string channelNameWork = channelName;
while (cleanName.Contains("/"))
{
if (channelNameWork.Contains("/"))
{
cleanName = channelNameWork.Remove(channelNameWork.IndexOf("/"), 1);
channelNameWork = cleanName;
}
}
string probeFile = cleanName + "." + channelIconExtension;
if (File.Exists(Path.Combine(channelIconPath, probeFile)))
{
channelIconFile = probeFile;
break;
}
}
if (channelIconFile != null) break;
}
channelIconCache[channelNumber] = channelIconFile;
return channelIconFile;
}
}
private class ChannelNumberComparer : IComparer
{
#region IComparer Members
public int Compare(object x, object y)
{
return ((Channel)x).channelNumber.CompareTo(((Channel)y).channelNumber);
}
#endregion
}
}
}